package cn.xiaoqi.task.config;

import cn.xiaoqi.task.job.DemoJob1;
import cn.xiaoqi.task.job.DemoJob2;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ScheduleConfiguration {

    public static class DemoJob01Configuration {

        @Bean
        public JobDetail demoJob1() {
            return JobBuilder.newJob(DemoJob1.class).withIdentity("demoJob01").storeDurably().build();
        }

        @Bean
        public Trigger demoJob01Trigger() {
            SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(5).repeatForever();
            return TriggerBuilder.newTrigger().forJob(demoJob1()).withIdentity("demoJob01Trigger").withSchedule(simpleScheduleBuilder).build();
        }

    }

    public static class DemoJob02Configuration {
        @Bean
        public JobDetail demoJob2() {
            return JobBuilder.newJob(DemoJob2.class).withIdentity("demoJob02").storeDurably().build();
        }

        @Bean
        public Trigger demoJob02Trigger() {
            SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(5).repeatForever();
            return TriggerBuilder.newTrigger().forJob(demoJob2()).withIdentity("demoJob02Trigger").withSchedule(simpleScheduleBuilder).build();
        }

    }
}
